﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Moving03.Administrator
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        public static int idquocgia1 = 0;
        public static int idquocgia2 = 0;
        DataClasses1DataContext context = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated == false || User.Identity.IsAuthenticated == true && !User.IsInRole("Admin"))
            {
                Response.Redirect("../Default.aspx");
            }
            Label1.Text = "";
        }

        protected void SqlDataSource3_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {

        }

        protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int index = e.RowIndex;
            DropDownList quocgia1 = GridView2.Rows[index].FindControl("DropDownList1") as DropDownList;
            Session["idquocgia1"] = int.Parse(quocgia1.SelectedValue);

            DropDownList quocgia2 = GridView2.Rows[index].FindControl("DropDownList2") as DropDownList;
            Session["idquocgia2"] = int.Parse(quocgia2.SelectedValue);

        }

        protected void SqlDataSource3_Updating(object sender, SqlDataSourceCommandEventArgs e)
        {
            string idquocgia1 = Session["idquocgia1"].ToString();
            string idquocgia2 = Session["idquocgia2"].ToString();
            e.Command.Parameters["@Id_QuocGia1"].Value = int.Parse(idquocgia1);
            e.Command.Parameters["@Id_QuocGia2"].Value = int.Parse(idquocgia2);

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemTuyenVanChuyen.aspx");
        }

        protected void GridView2_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {
            if (e.Exception != null)
            {

                Label1.Text = e.Exception.Message;
                e.ExceptionHandled = true;
            }
            else if (e.AffectedRows != 0)
            {
                string a = "<script language='javascript'>  window.alert('Delete Thành Công') </script>";
                Response.Write(a);
                Label1.Text = "";
            }
        }


    }
}
